<?php
/**
 * View Nuovo Post - LaFabbrica.org
 * 
 * @author     luigi.pastore (gigi@la-fabbrica.org)
 * @created    21-apr-2011
 * @package    LaFabbrica
 * @copyright  Copyright (c) 2011 Luigi Pastore
 */
?>
<script type="text/javascript" src="/js/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="/js/ckeditor/adapters/jquery.js"></script>
<script type="text/javascript" src="/js/ckeditor/load-editor.js"></script>
<script type="text/javascript">
//<![CDATA[
    $(document).ready(function() {
        
        validator.groups = {location_street: "address", location_city: "address", location_province_id: "address"}
        $("#location_name").rules("add", {
            required: true,
            messages: {
                required: "<?php echo ERR_EMPTY ?>"
            }
        });

        $("#location_street").rules("add", {
            required: true,
            messages: {
                required: "<?php echo ERR_EMPTY ?>"
            }
        });

        $("#location_city").rules("add", {
            required: true,
            messages: {
                required: "<?php echo ERR_EMPTY ?>"
            }
        });

        $("#location_province_id").rules("add", {
            required: true,
            messages: {
                required: "<?php echo ERR_EMPTY ?>"
            }
        });

        $("#location_cap").rules("add", {
            digits: true,
            rangelength: [5, 5],
            range: [0, 98100],
            messages: {
                digits : "<?php echo  sprintf( ERR_FORMAT, 'CAP' )?>",
                rangelength : "<?php echo  sprintf( ERR_FORMAT, 'CAP' )?>",
                range : "<?php echo  sprintf( ERR_FORMAT, 'CAP' )?>"
            }
        });

	$( '#location_desc' ).ckeditor(function(){}, ckeditorConf );
        
	// Risolve un bug d'integrazione tra jQuery e CKeditor
	$("#salva").click(function(){
            CKEDITOR.instances.location_desc.updateElement();
            return validator.element( "#location_desc" );
        });
	
	$('#location_desc').val('<?php echo (addslashes($this->data['location_desc']))?>');

    });

    
    //]]>
</script>

<div class="info">
    <h2>Inserisci Nuova Location</h2>
    <div>Per inserire un nuovo post...</div>
    <div>I campi contrassegnati da <span class="req">*</span> sono obbligatori!</div>
</div>
<!-- This <div> holds alert messages to be display in the sample page. -->
<div id="alerts">
    <noscript>
    <p>
	<strong>CKEditor requires JavaScript to run</strong>. In a browser with no JavaScript
				support, like yours, you should still see the contents (HTML data) and you should
				be able to edit it normally, without a rich editor interface.
    </p>
    </noscript>
</div>
<form class="fab" name="locationForm" id="locationForm" action="/admin/location/info/id/<?php echo $this->location_id ?>" method="post" enctype="multipart/form-data">
    <ul>
	<li class="paging-context ">
	    <table class="pgStyle1 circle2" cellspacing="0">
		<tr>
		    <td class="c selected">
			<var>1</var>
		    </td>
		    <td class="t selected">
			<b id="pagecircle1">Dettagli Location</b>
		    </td>
		    <td class="c ">
			<var>2</var>
		    </td>
		    <td class="t">
			<b id="pagecircle2">Aggiungi Contatti</b>
		    </td>
		</tr>
	    </table>
	</li>
    </ul>
<div id="content">    
    <ul>
	<li id="errorLi" style="<?php echo $this->errorMsg ? '' : 'display:none'?>">
	    <h3 id="errorMsgLbl">Si &egrave; verificato un problema durante l'invio del modulo.</h3>
	    <p id="errorMsg">
		Di seguito trovi evidenziati gli errori riscontrati. <?php var_dump($this->errorMsg) ?>
	    </p>
	</li>
	
	<li class="<?php echo $this->errorMsg['location_name'] ? 'error' : ''?>">
	    <label class="desc <?php echo $this->errorMsg['location_name'] ? 'error' : ''?>">Nome Location<span class="req">*</span></label>
	    <div>
		<span>
		    <input id="location_name" name="location_name" class="field text small" type="text" maxlength="255" value="<?php echo $this->data['location_name']?>" /> 
		</span>
	    </div>
	    <p class="error" style="<?php echo $this->errorMsg['location_name'] ? 'display:block' : ''?>"><?php echo $this->errorMsg['location_name']?></p>
	</li>
	
	<li class="complex <?php echo $this->errorMsg['location_address'] ? 'error' : ''?>">
	    <label class="desc <?php echo $this->errorMsg['location_address'] ? 'error' : ''?>">Indirizzo<span class="req">*</span></label>
	    <div>
		<span class="input">
		    <input class="field text addr" name="location_street" id="location_street" size="50" type="text" value="<?php echo $this->data['location_street']?>" />
		    <label>Via</label>
		</span>
		<span class="input">
		    <input class="field text addr" name="location_street_number" id="location_street_number" size="2" type="text" value="<?php echo $this->data['location_street_number']?>" />
		    <label>N&deg;</label>
		</span>
		<span class="input">
		    <input class="field text addr" name="location_loc" id="location_loc" size="50" type="text" value="<?php echo $this->data['location_loc']?>" />
		    <label>Localit&aacute;</label>
		</span>
		<span class="input">
		    <input class="field text addr" name="location_city" id="location_city" size="50" type="text" value="<?php echo $this->data['location_city']?>" />
		    <label>Citt&aacute;</label>
		</span>
		<span class="input">
		    <input class="field text addr" name="location_cap" id="location_cap" size="10" type="text" value="<?php echo $this->data['location_cap']?>" />
		    <label>CAP</label>
		</span>

		<span class="left">
		    <select class="field select addr" name="location_province_id" id="location_province_id">
                        <option value="">-- Seleziona provincia --</option>
			<?php foreach($this->province AS $k => $provincia): ?>
			<option value="<?php echo $k?>" <?php echo $this->data['location_province_id'] == $k ? 'selected="selected"' : '' ?> ><?php echo $provincia['province_long_name']?></option>
			<?php endforeach; ?>
		    </select>
		    <label>Provincia</label>
		</span>
		<p class="error" style="<?php echo $this->errorMsg['location_address'] ? 'display:block' : ''?>"><?php echo $this->errorMsg['location_address']?></p>
	    </div>
	</li>	
	
	<li class="section">
	    <h3></h3>
	</li>	
	
	<li class="<?php echo $this->errorMsg['location_desc'] ? 'error' : ''?>">
	    <label class="desc <?php echo $this->errorMsg['location_desc'] ? 'error' : ''?>">Info Locale</label>
	    <div>
		<span>
		    <textarea id="location_desc" name="location_desc" rows="5" cols="10"><?php echo htmlentities( $this->data['location_desc'] )?></textarea>
		</span>
	    </div>
	    <p class="error" style="<?php echo $this->errorMsg['location_desc'] ? 'display:block' : ''?>"><?php echo $this->errorMsg['location_desc']?></p>
	</li>

    </ul>
</div>
    <div id="formButtons">
        <button id="salva" type="submit" name="salva" value="salva" class="button positive">
            <img src="/images/admin/tick.png" alt="" />Continua
        </button>
        <button id="annulla" name="annulla" value="annulla" class="button negative">
            <img src="/images/admin/cross.png" alt="" />Annulla
        </button>
    </div>
</form>
